package cn.com.swu.mianyangapp;

import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.appcompat.app.ActionBar;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import cn.com.swu.mianyangapp.databinding.ActivityMainBinding;
import cn.com.swu.mianyangapp.ui.home.HomeFragment;
import cn.com.swu.mianyangapp.ui.message.MessageFragment;
import cn.com.swu.mianyangapp.ui.notifications.NotificationsFragment;
import cn.com.swu.mianyangapp.ui.todo.TodoFragment;


public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        BottomNavigationView navView = findViewById(R.id.nav_view);
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.navigation_home, R.id.navigation_todo, R.id.navigation_notifications, R.id.navigation_message)
                .build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main);
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(binding.navView, navController);
    }


    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        switch (item.getItemId()){
            case R.id.navigation_home:
                fragmentTransaction.replace(R.id.nav_host_fragment_activity_main, new HomeFragment()).commit();
                return true;
            case R.id.navigation_todo:
                fragmentTransaction.replace(R.id.nav_host_fragment_activity_main,new TodoFragment()).commit();
                return true;
            case R.id.navigation_notifications:
                fragmentTransaction.replace(R.id.nav_host_fragment_activity_main,new NotificationsFragment()).commit();
                return true;
            case R.id.navigation_message:
                fragmentTransaction.replace(R.id.nav_host_fragment_activity_main,new MessageFragment()).commit();
                return true;
        }
        return true;
    }
}